package sis.testing;/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-07-30 21:39
 * @notify
 * @version 1.0
 */

import junit.framework.TestCase;
import junit.framework.TestSuite;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class SuiteBuliderTest extends TestCase {
    public void testGatherTestClassNames() {
        SuiteBuilder builder = new SuiteBuilder();
        List<String> classes = builder.gatherTestClassNames();
        assertTrue(classes.contains("sis.testing.SuiteBuliderTest"));
        assertFalse(classes.contains("sis.testing.NotATestClass"));
    }

    public void testCreateSuite() {
        SuiteBuilder builder = new SuiteBuilder() {
            public List<String> gatherTestClassNames() {
                List<String> classNames = new ArrayList<>();
                classNames.add("testing.SuiteBuilderTest");
                return classNames;
            }
        };
        List<String> classes = builder.gatherTestClassNames();
        assertTrue(classes.contains("testing.SuiteBuilderTest"));
    }

    public boolean contains(TestSuite suite, Class testClass) {
        List testClasses = Collections.list(suite.tests());
        for (Object object : testClasses) {
            if (object.getClass() == TestSuite.class) {
                if (contains((TestSuite) object, testClass)) {
                    return true;
                }
            }
            if (object.getClass() == testClass) {
                return true;
            }
        }
        return false;
    }
}
